package day17;

import template.template;

import java.io.*;
import java.util.StringTokenizer;

public class demo2 {

    private static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static Read read=new Read();
    public static void main(String[] args) throws IOException {
        int n=read.nextInteger();
        int m= read.nextInteger();
        int [][]arr=new int[n][m];
        int []line=new int[n];
        int[]row=new int[m];
        for (int i = 0; i <n ; i++) {
            for (int j = 0; j <m ; j++) {
                arr[i][j]=read.nextInteger();
                line[i]+=arr[i][j];
                row[j]+=arr[i][j];
            }
        }
        for (int i = 0; i <n ; i++) {
            for (int j = 0; j <m ; j++) {
                out.print(line[i]+row[j]-arr[i][j]+" ");
            }
        out.println();
        }


    }



    static class Read{

        StringTokenizer st=new StringTokenizer("");
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));

        String next() throws IOException {
            while (st.hasMoreTokens()){
                st=new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
         }

        Integer nextInteger() throws IOException {
            return Integer.parseInt(next());
        }

    }

}
